<?php include_once("common.php");
class Role extends BaseEntity implements BaseOperations
{
	private $name;
	private $itemsTab;
	private $categoriesTab;
	private $rolesTab;
	private $usersTab;
	
	// PROPERTIES
	public function setName($label)
	{
		$this->name=$label;
	}
	public function getName()
	{
		return $this->name;
	}
	
	public function setAccessToItemsTab($access)
	{
		$this->itemsTab=$access;
	}
	
	public function getAccessToItemsTab()
	{
		return $this->itemsTab;
	}
	
	public function setAccessToCategoriesTab($access)
	{
		$this->categoriesTab=$access;
	}
	
	public function getAccessToCategoriesTab()
	{
		return $this->categoriesTab;
	}
	
	public function setAccessToRolesTab($access)
	{
		$this->rolesTab=$access;
	}
	
	public function getAccessToRolesTab()
	{
		return $this->rolesTab;
	}
	
	public function setAccessToUsersTab($access)
	{
		$this->usersTab=$access;
	}
	
	public function getAccessToUsersTab()
	{
		return $this->usersTab;
	}
	
	// METHODS
	public function GetRecordById($id)
	{
		$res = mysql_query("SELECT * FROM roles WHERE id = ".$id);
		
		$f = mysql_fetch_array($res);
				
		$tmp = new Role;
		$tmp->setId($f[id]);
		$tmp->setName($f[label]);
		$tmp->setAccessToItemsTab($f[itemAccess]);
		$tmp->setAccessToCategoriesTab($f[categoryAccess]);
		$tmp->setAccessToRolesTab($f[roleAccess]);	
		$tmp->setAccessToUsersTab($f[userAccess]);		
		
		return $tmp;
	}
	
	public function GetAllRecords()
	{
		$result = array();
			
		$res = mysql_query("SELECT * FROM roles;");
		
		for ($c=0; $c<mysql_num_rows($res); $c++)
		{
			$f = mysql_fetch_array($res);
			
			$tmp = new Role;
			$tmp->setId($f[id]);
			$tmp->setName($f[label]);
			$tmp->setAccessToItemsTab($f[itemAccess]);
			$tmp->setAccessToCategoriesTab($f[categoryAccess]);
			$tmp->setAccessToRolesTab($f[roleAccess]);	
			$tmp->setAccessToUsersTab($f[userAccess]);
			
			$result[] = $tmp;
		}
		
		return $result;
	}
	
	public function AddNewRecord()
	{
		// should be implemented
	}
	
		public function UpdateRecord()
	{
		// should be implemented
	}
	
	public function RemoveRecordById($id)
	{
		// should be implemented
		}
}
?>